{% extends 'html/base_template.html' %}

{% block top_script_section %}
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />

    <script type="text/javascript">
        function confirm(id, ok) {
            if (ok) {
                $.post("{{ urls.confirm }}", {
                    "id": id,
                    "type": "confirm",
                    "flag": 1,
                    "description": null
                }, function (data) {

                    if (data.rltcode == 0) {
                        $('#example-1').dataTable()._fnAjaxUpdate();
                    } else {
                        $.modal.alert(data.rltmsg)
                    }
                });
            } else {
                $("input[name='id']").attr('value', id)
                $("#id_dialog_form").dialog("open");
            }
        }</script>
{% endblock %}

{% block content_section %}
    {% load static %}

    <div id="id_dialog_form" title="请填写打回报告">
        <form>
            <fieldset>
                <div>
                    <input type="text" name="id" style="display: none">
                    <textarea style="margin: 20px;width: 520px;height: 230px;" id="id_result" class="text ui-widget-content ui-corner-all" rows="" cols=""></textarea>
                </div>
            </fieldset>
        </form>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">资质审核列表</h3>
        </div>
        <div class="panel-body">
            <script type="text/javascript">
                jQuery(document).ready(function ($) {
                    $("#id_dialog_form").dialog({
                        autoOpen: false,
                        height: 400,
                        width: 600,
                        modal: true,
                        title: "",
                        buttons: {
                            "提交": function() {
                                $.post("{{ urls.confirm }}", {
                                    "id": $("input[name='id']").val(),
                                    "type": "confirm",
                                    "flag": 0,
                                    "description": $("#id_result").val()
                                }, function (data) {
                                    if (data.rltcode == 0) {
                                        $('#example-1').dataTable()._fnAjaxUpdate();
                                    } else {
                                        $.modal.alert(data.rltmsg)
                                    }
                                });
                                $(this).dialog("close");
                            },
                            "取消": function() {
                                $(this).dialog("close");
                            }
                        }
                    });


                    TableTools.DEFAULTS.aButtons = ["csv", "xls"];
                    $("#example-1").dataTable({
                        dom: "<'col-xs-9'<'col-xs-6'l><'col-xs-6'f>r>" +
                        "t" +
                        "<''<'col-xs-6'i><'col-xs-6'p>>",
{#                        dom:'<"H"lTfr>t<"F"ip>',#}
                        aLengthMenu: [
                            [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]
                        ],
                        bProcessing: true,
                        bPaginate: true,
                        fnDraw: false,
                        bLengthChange: true,
                        bStateSave: false,
                        bServerSide: true,
                        bDestroy: true,
                        sServerMethod: "POST",
                        sAjaxSource: "{{ urls.query }}",
                        fnServerParams: function (aoData) {
                            aoData.push({'name': 'type', 'value': 'query'});
                            aoData.push({'name': 'status', 'value': {{ Status.kInAuditing }}});
                        },
                        columns: [
                            {"data": "index"},
                            {"data": "name"},
                            {"data": "company"},
                            {"data": "ctime"},
                            {"data": "id", "render":function(obj){
                               return '<a href="{{ urls.query }}?id='+obj+'" class="btn btn-info btn-sm btn-icon icon-left">查看</a>';
                            }},
                            {
                                "data": "id", "render": function (obj) {
                                return '<div><a onclick="confirm('+obj+','+1+');'+'" class="btn btn-secondary btn-sm btn-icon">通过</a>' +
                                        '<a onclick="confirm('+obj+','+0+');'+'" class="btn btn-danger btn-sm btn-icon icon-left">打回</a></div>';
                            }
                            }

                        ],
                        language: {
                            "sProcessing": "处理中...",
                            "sLengthMenu": "每页显示 _MENU_ 条结果",
                            "sZeroRecords": "没有匹配结果",
                            "info": "第 _PAGE_ 页 ( 总共 _PAGES_ 页 ,_TOTAL_条)",
                            "sInfoEmpty": "显示第 0 至 0 条结果，共 0 条",
                            "infoFiltered": "(从 _MAX_ 条记录过滤)",
                            "sInfoPostFix": "",
                            "sSearch": "模糊搜索:",
                            "sUrl": "",
                            "sEmptyTable": "表中数据为空",
                            "sLoadingRecords": "载入中...",
                            "sProcessing": "<img src='assets/images/loding.gif'/> 正在加载数据...",
                            "sInfoThousands": ",",
                            "oPaginate": {
                                "sFirst": "首页",
                                "sPrevious": "上页",
                                "sNext": "下页",
                                "sLast": "末页"
                            }
                        }
                    });
{#                    var $state = $("#example-1 thead input[type='checkbox']");#}
{#                    $("#example-1").on('draw.dt', function () {#}
{#                        cbr_replace();#}
{#                        $state.trigger('change');#}
{#                    });#}
{#                    // Script to select all checkboxes#}
{#                    $state.on('change', function (ev) {#}
{#                        var $chcks = $("#example-1 tbody input[type='checkbox']");#}
{#                        if ($state.is(':checked')) {#}
{#                            $chcks.prop('checked', true).trigger('change');#}
{#                        }#}
{#                        else {#}
{#                            $chcks.prop('checked', false).trigger('change');#}
{#                        }#}
{#                    });#}
                });
            </script>
            <div class="col-xs-3 table_but">
                <a href="#">导出当页</a>
                <a href="#">选择导出</a>
                <a href="#">批量通过</a>
            </div>
            <table class="table table-bordered table-striped" id="example-1">
                <thead>
                <tr>
{#                    <th class="no-sorting">#}
{#                        <input type="checkbox" class="cbr">#}
{#                    </th>#}
                    <th></th>
                    <th>账号名</th>
                    <th>公司名称</th>
                    <th>提交时间</th>
                    <th>账号信息</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody class="middle-align">
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}